package com.media.entrance.controller;

import com.media.entrance.model.BatchResultDataModel;
import com.media.entrance.model.BatchResultModel;
import com.media.entrance.model.MatchAndResourceModel;
import com.media.entrance.service.MatchService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

//二期客户接口
@Controller
@RequestMapping("/client")
@Slf4j
public class ClientController {

    @Autowired
    private MatchService matchService;

    //同步接口
    @ResponseBody
    @RequestMapping(value = "/requestMatchAgent/deviceId={deviceId}", method = RequestMethod.GET)
    public BatchResultModel requestMatchAgentSync(@PathVariable("deviceId") String deviceId){
        if (deviceId == null) {
            return new BatchResultModel("illegal input parameters", "deviceId is null", null);
        }
        // 匹配坐席
        MatchAndResourceModel matchInfo = matchService.requestMatchAgentNew(deviceId);
        matchService.recordAgentChangeRecords(matchInfo);
        BatchResultDataModel data = new BatchResultDataModel();
        if (matchInfo.getAgentId() != null) {
            data.setMatching(matchInfo);
        } else {
            data.setUnmatch(matchInfo);
        }
        return new BatchResultModel("success", "match result", data);
    }

    @ResponseBody
    @RequestMapping(value = "/cancelMatch/deviceId={deviceId}", method = RequestMethod.GET)
    public BatchResultModel cancelMatch(@PathVariable("deviceId") String deviceId){
        if (deviceId == null) {
            return new BatchResultModel("illegal input parameters", "deviceId is null", null);
        }
        matchService.cancelMatch(deviceId);
        return new BatchResultModel("success", "clean done", null);
    }
}
